package org.wk.account.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wk.account.service.ConfigService;
import org.wk.account.view.ConfigVo;
import org.wk.core.common.view.PageVo;
import org.wk.core.common.view.ResponseVo;
import org.wk.logger.common.annotation.SysLog;

import java.util.Map;

/**
 * @author TangShenShen
 * @Description: 账户管理的参数设置
 * @date 2018/6/5 11:52
 */
@RestController
@RequestMapping("/accounts/config")
public class AccountConfigController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ConfigService configService;

    /**
     * 配置参数分页列表
     */
    @SysLog("账户参数管理列表")
    @RequestMapping("/list")
    public ResponseVo list(@RequestParam Map<String, Object> params){
        PageVo page = configService.queryPage(params);

        return ResponseVo.success().addAttribute("page", page);
    }

    /**
     * 配置参数信息
     */
    @SysLog("账户参数信息")
    @RequestMapping("/info/{configId}")
    public ResponseVo info(@PathVariable("configId") String configId){
        ConfigVo configVo = configService.selectById(configId);
        return ResponseVo.success().addAttribute ("config", configVo);
    }

    /**
     * 保存参数配置
     */
    @SysLog("账户参数保存")
    @RequestMapping("/save")
    public ResponseVo save(@RequestBody ConfigVo config){
        configService.saveOrUpdate(config);
        return ResponseVo.success();
    }

    /**
     * 更新参数配置
     */
    @SysLog("账户参数更新")
    @RequestMapping("/update")
    public ResponseVo update(@RequestBody ConfigVo config){
        configService.saveOrUpdate(config);
        return ResponseVo.success();
    }


}
